//
//  MVCViewController.m
//  TableViewDataSource
//
//  Created by hibo on 2019/6/10.
//  Copyright © 2019 hibo. All rights reserved.
//

#import "MVCViewController.h"
#import "MVCTableViewCell.h"
#import "Model.h"
#import "Present.h"
#import "TableViewDataSource.h"
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height


@interface MVCViewController ()

@property (nonatomic,strong) Present *present;
@property (nonatomic,strong) UITableView *tableview;
@property (nonatomic,strong) TableViewDataSource *dataSource;
@property (nonatomic,strong) TableViewDelegate *delegate;

@end

@implementation MVCViewController

-(Present *)present{
    if (_present==nil) {
        _present = [[Present alloc] init];
    }
    return _present;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableview];
}
#pragma mark - 创建列表
-(UITableView *)tableview{
    if (_tableview==nil) {
        _tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        [_tableview registerClass:[MVCTableViewCell class] forCellReuseIdentifier:@"cell"];
        _tableview.tableFooterView = [UIView new];
        self.dataSource = [[TableViewDataSource alloc] initWithDataArr:self.present.dataArr identifier:@"cell" configureCellBlock:^(MVCTableViewCell *cell, Model *model, NSIndexPath *indexPath) {
             cell.model = model;
        }];
        self.tableview.dataSource = self.dataSource;
        self.delegate = [[TableViewDelegate alloc]initWithRowHeight:^CGFloat(NSIndexPath *indexPath) {
            return 60;
        } headerHeight:^CGFloat(NSInteger section) {
            return 10;
        } footerHeight:^CGFloat(NSInteger section) {
            return 10;
        } header:nil footer:nil];
        self.tableview.delegate = self.delegate;
    }
    return _tableview;
}

@end
